home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / filestatus / dirs.c next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.5 KB  |  120 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <functions.h>
  6. #define NL NULL
  7. char image[200];
  8. void sr(char *str);
  9. void CheckFiles(void);
  10. void end();
  11. int CheckForDirs(char PathsFile[]);
  12. int NumDirs;
  13. main(int argc,char *argv[])
  14. {
  15.   if(argc!=2)
  16.   {
  17.         printf("DirStatus v1.0, written by Joseph Hodge\n");
  18.         printf("Usage: DirStatus <conference path>\n");
  19.         printf("   ie: DirStatus BBS:PD\n");
  20.         printf("\n");
  21.         exit(0);
  22.   }
  23.  strcpy(image,argv[1]);
  24.  sr(image);
  25.   printf("\nDirStatus v1.0, written by Joseph Hodge\n");
  26.   printf("\n\nPerforming validation..\n\n");
  27.    CheckFiles();
  28.    end();
  29. }
  30.  
  31. void CheckFiles(void)
  32. {
  33.    FILE *fi;
  34.    char PathsFile[200];
  35.    char Dirs[200];
  36.    int i=0;
  37.    int NumFound=0;
  38.    int NumLost=0;
  39.    sprintf(Dirs,"%s/ndirs",image);
  40.    sprintf(PathsFile,"%s/Paths",image);
  41.    
  42.    if(access(PathsFile,00))
  43.    {
  44.      printf("Can't locate paths file\n");
  45.      printf("Please check to insure the conference path was correct. IE:\n");
  46.      printf("BBS:PD\n");
  47.      end();
  48.    }
  49.    if(access(Dirs,00))
  50.    {
  51.     printf("Can't locate ndirs file\n");
  52.      printf("Please check to insure the conference path was correct. IE:\n");
  53.      printf("BBS:PD\n");
  54.      end();
  55.    }
  56.    fi=fopen(Dirs,"r");
  57.    fgets(Dirs,80,fi);
  58.    fclose(fi);
  59.    NumDirs=atoi(Dirs);
  60.    i=1;
  61.    while(i<=NumDirs)
  62.    {
  63. printf("\nScanning dir%d...\n",i);
  64.      sprintf(PathsFile,"%s/dir%d",image,i);
  65.      
  66.      NumFound=0; NumLost=0;
  67.      fi=fopen(PathsFile,"r");
  68.      if(fi!=NULL)
  69.      {
  70.        while(fgets(PathsFile,80,fi)!=NULL)
  71.        {
  72.           if(PathsFile[0]>32 && (PathsFile[13]=='P' || PathsFile[13]=='N'))
  73.           {
  74.             sr(PathsFile);
  75.             if(!CheckForDirs(PathsFile)) NumLost +=1;
  76.             NumFound +=1; 
  77.           }
  78.        }
  79.   
  80.        fclose(fi);
  81.        printf("\n  Total Files %d, Total missing %d\n",NumFound,NumLost);
  82.      }
  83.      else printf("  Can't locate dir\n\n");
  84.      i++;
  85.     }
  86. }
  87. int CheckForDirs(char PathsFile[])
  88. {
  89.    FILE *fi;
  90.    char DirFile[200];
  91.    char FileName[20];
  92.    sprintf(FileName,"%-13.13s",PathsFile);
  93.    sr(FileName);
  94.    sprintf(DirFile,"%s/paths",image);
  95.    fi=fopen(DirFile,"r");
  96.    while(fgets(DirFile,80,fi)!=NULL)
  97.    {
  98.       sr(DirFile);
  99.       strcat(DirFile,FileName);
  100.       if(!access(DirFile,00)) { fclose(fi); return(1); }
  101.    }
  102.    fclose(fi);
  103.    printf("  Can't locate file %s\n",FileName);
  104.    return(0);
  105. }
  106. void sr(char *str)
  107. {
  108.    register int i;
  109.    i=strlen(str)-1;
  110.    while(i)
  111.    {
  112.       if(*(str+i)<=32) *(str+i)='\0'; else return;
  113.       i--;
  114.    }
  115. }
  116.  
  117. void end()
  118. {
  119.   exit(0);
  120. }